// 父类:公共属性和方法
function Person(name, age, friends) {
  // stu.name = nme
  this.name = name
  this.age = age
  this.friends = friends
}
Person.prototype.eating = function () {
  console.log(this.name + 'eating');
}



// 子类:特有属性和方法
function Student(name, age, friends, sno) {
  Person.call(this, name, age, friends)
  this.sno = sno
}

Student.prototype = new Person()

Student.prototype.studying = function () {
  console.log(this.name + 'studying');
}

var stu = new Student('why', 19, ['kobe'], '01')
console.log(stu);

// 2.创建出来两个stu对象
var s1 = new Student('s1', 20, ['s111'], '02')
var s2 = new Student('s2', 22, ['s222'], '03')

// 获取引用,修改引用中的值,会相互影响
s1.friends.push('kobe')
console.log(s1.friends);
console.log(s2.friends);


// 弊端:
// 1.Person函数至少被调用了两次
// 2.Person原型对象上也多出来这几个属性:值为undefined